import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from "@/views/layout"

Vue.use(VueRouter)

// 静态路由：登录页等不需要权限的页面
const constantRoutes = [
  { path: "/", redirect: "/login" },
  { path: "/login", component: () => import("@/views/login") },
]

const router = new VueRouter({
  routes: constantRoutes
})

// 动态路由（根据权限控制）
export const asyncRoutes = [
  {
    path: "/layout",
    component: Layout,
    redirect: "/tool/toollist",
    children: [
      {
        path: "/tool/toollist",
        component: () => import("@/components/toollist.vue")
      },
      {
        path: "/target/tagetlist",
        component: () => import("@/components/target")
      },
      {
        path: "/target/upload",
        component: () => import("@/components/upload.vue")
      },
      
      {
        path: "/tool/upload",
        component: () => import("@/components/toolupload.vue")
      },
      {
        path: "/user/userlist",
        component: () => import("@/components/userlist.vue")
      },
      {
        path: "/user/userlog",
        component: () => import("@/components/operate.vue")
      },
      {
        path: "/user/usermanage",
        component: () => import("@/components/manage.vue")
      },
      {
        path: "/tool/condition",
        component: () => import("@/components/condition.vue")
      },
    ]
  }
]

// 在登录成功后动态添加路由
export function addAsyncRoutes() {
  asyncRoutes.forEach(route => {
    router.addRoute(route)  // 使用 addRoute 替代 addRoutes
  })
}

export default router
